import {BaseData, MainData, PK} from "../../coreModule/data/BaseData";
import {field} from "../../coreModule/data/DataLoader";
import {Task} from "./Task";

export enum ParticRecordType {
    Military, Reward, PartTime, Camp
}

export enum ParticRecordStatus {
    Normal, Exit
}

export class MemberInfo extends BaseData {
    @field
    public name: string = "";
    @field
    public cardNo: string = "";
}

export class ParticInfo extends BaseData {
    @field([MemberInfo])
    public members: MemberInfo[] = [new MemberInfo()];
    @field
    public name: string = "";
    @field
    public phone: string = "";
}

export class ParticRecord extends MainData {

    @field(String)
    public userId: PK;
    @field(String)
    public taskId: PK;

    @field(ParticInfo)
    public infos?: ParticInfo;
    @field(Number)
    public count: number = 1;

    @field(Number)
    public createdAt: number;
    @field(Number)
    public status: ParticRecordStatus = ParticRecordStatus.Normal;

    @field(String)
    public nickName: string;
    @field(String)
    public displayName: string;
    @field(String)
    public avatarUrl: string;
    @field(String)
    public phone: string;

    /**
     * 创建
     */
    public static create(userId, taskId) {
        const res = new ParticRecord();
        res.taskId = taskId;
        res.userId = userId;
        res.status = ParticRecordStatus.Exit;

        res.createdAt = Date.now();
        return res;
    }
}

